package com.job2e.common;

import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.code.jbauble.dao.AbstractDao;
import com.google.code.jbauble.dao.Query;

public class CRUDDao<T> extends AbstractDao {
	private Class<T> entityClass = null;
	
	public CRUDDao() {
		super();
		entityClass =(Class<T>) ((ParameterizedType) getClass()
                .getGenericSuperclass()).getActualTypeArguments()[0];
	}
	
	public T getById(Object id) {
		Query q = this.datastore.createQuery(entityClass).filter("id =", id);
		return (T)q.get();
	}
	
	public void save(T t) {
		this.datastore.save(t);
	}
	
	public void delete(Long id) {
		Query q = this.datastore.createQuery(entityClass).filter("id =", id);
		this.datastore.delete(q);
	}
	
	public void delete(Object id) {
		Query q = this.datastore.createQuery(entityClass).filter("id =", id);
		this.datastore.delete(q);
	}
}
